﻿using RuoVea.ExEnum;
using RuoVea.ExPws;
using RuoVea.OmiApi.User.Service;
using RuoVea.OmiApi.User.Service.Dto;
using ShiSan.Blog.Server.Language;

namespace ShiSan.Blog.Web.Controllers;

[Authorize]
public class AuthExtendController : Controller
{
    private readonly IPasswordServer _passwordServer;
    private readonly SysUserService _sysUserService;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sysUserService"></param>
    /// <param name="passwordServer"></param>
    public AuthExtendController(  SysUserService sysUserService, IPasswordServer passwordServer)
    {
        _sysUserService = sysUserService;
        _passwordServer = passwordServer;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [HttpGet("user/baseinfo")]
    public async Task<RestfulResult> BaseInfo()
    {
        RestfulResult restful = new RestfulResult { Code = CodeStatus.OK };
        restful.Data = await _sysUserService.GetBaseInfo();
        return restful;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [HttpPost("user/changepwd")]
    public async Task<RestfulResult> ChangePwd([FromBody] ChangePwdInput input)
    {
        RestfulResult restful = new RestfulResult { Code = CodeStatus.OK };
        input.PasswordOld = _passwordServer.Encrypt(input.PasswordOld);
        if (await _sysUserService.ChangePwd(input) > 0)
        {
            restful.Data = true;
        }
        else
        {
            restful.Message = $"{i18n.modify}{i18n.fail}";
            restful.Code = CodeStatus.BadRequest;
        }
        return restful;
    }
}
